home *** CD-ROM | disk | FTP | other *** search
- Path: news.nbnet.nb.ca!news
- From: lewwid@brunswickmicro.nb.ca (Jeff)
- Newsgroups: comp.lang.c
- Subject: Can anyone help a newbie out ?
- Date: Fri, 12 Apr 1996 02:38:04 GMT
- Organization: NBNet
- Message-ID: <4kkf3r$5b0@darwin.nbnet.nb.ca>
- NNTP-Posting-Host: 198.164.26.48
- X-Newsreader: Forte Free Agent 1.0.82
-
- I started reading a book on C, and i am stuck on one exercise, and i
- know it's really simple, but i can't do it :(
-
- Problem:Write a function that accepts two strings. Count the number
- of characters in each string, and return the pointer to the longer
- string.
-
- This is what my lamer brain had to say ...
-
- #include <stdio.h>
-
- char *ptr, *ptr1;
-
- char checksize(char x[], char y[]);
-
- main()
- {
- /* Prompt for input */
-
- puts("Please enter in the first string :");
- gets(ptr);
- puts("Now the second :");
- gets(ptr1);
-
- /* Print the longest pointer, and call checksize */
-
- printf("The char array that was longer is : %s", checksize(ptr,
- ptr1));
-
- return 0;
- }
- /* Checksize .. checks to see which array of char is longer, and
- returns the longest of the 2 */
- char checksize(char x[], char y[])
- {
- int count, int total = 0, int total1 = 0;
-
- while (*x != NULL)
- total += 1
-
- while (*y != NULL)
- total1 += 1
-
- if (total < total2)
- return *y;
- if (total > total2)
- return *x;
- }
-
-
- Yes i know, this is messy and very bad, but i am just starting out :)
-
- If someone could email me with any help, and good pointers, that would
- be greatly appreciated ..
-
- lewwid@brunswickmicro.nb.ca
-
-